package com.lgx.right.dao.impl;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import com.lgx.common.basic.dao.GeneralDao;

import com.lgx.common.exception.DataException;
import com.lgx.right.dao.ICardDao;
import com.lgx.right.entity.Card;

/**
 * 
 * @author acer
 *
 */
@Component("cardDao")
public class CardDao extends GeneralDao implements ICardDao {

	protected Logger log = Logger.getLogger(this.getClass());
	
	public Card createCard(Card card) throws DataException {
		this.getHibernateTemplate().save(card);
		log.info("[创建会员卡]:"+card.getId());
		return card;
	}

	public Card updateCard(Card card) throws DataException {
		this.getHibernateTemplate().update(card);
		log.info("[更新会员卡]:"+card.getId());
		return card;
	}

	public void deleteCard(Card card) throws DataException {
		log.info("[删除会员卡]:"+card.getId());
		this.getHibernateTemplate().delete(card);
	}

	public void deleteCard(String id) throws DataException {
		this.deleteCard(this.findCardById(id));
		log.info("[删除会员卡]:"+id);
	}

	public Card findCardById(String id) {
		return this.getHibernateTemplate().get(Card.class, id);
	}

}
